package org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.domain.AbstractAggregateRoot;

import java.io.Serial;
import java.io.Serializable;
import java.time.Instant;

@Entity
@Table(name="user_activity")
@AllArgsConstructor
public class UserActivityParticipation extends AbstractAggregateRoot<UserActivityParticipation> implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    @Id
    private Integer id;

    @Setter
    private Integer userId;

    @ManyToOne(fetch = FetchType.LAZY)
    private ActivityItem activityItem;

    @Getter
    private boolean finished;

    private Instant createTime;
    private Instant updateTime;

    protected UserActivityParticipation() {}

    public void markAsFinished() {
        if (!this.finished) {
            this.finished = true;
            this.updateTime = Instant.now();
        }
    }

}

